/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package au.edu.swin.swinvehicle.vehicle;

import au.edu.swin.swinvehicle.vehiclelicencetype.VehicleLicenceTypeEntity;
import au.edu.swin.swinvehicle.vehicletype.VehicleTypeEntity;
import java.io.Serializable;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author Administrator
 */
@Entity
@NamedQueries({
    @NamedQuery(name = "findAllVehicles",
    query = "SELECT v FROM VehicleEntity v WHERE v.deleted = false")
})
@Table(name = "VEHICLE")
public class VehicleEntity implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Column(length = 60, nullable = false)
    private String name;
    @Column(length = 255, nullable = false)
    private String description;
    @Column(length = 100, nullable = false)
    private String makeAndModel;
    @Column(length = 30, nullable = false)
    private String colour;
    @Column(name = "PROD_YEAR", nullable = false)
    private Integer year;
    @Column(nullable = false)
    private Boolean deleted;
    @ManyToOne(optional = false, cascade = CascadeType.PERSIST)
    private VehicleTypeEntity vehicleType;
    @ManyToOne(optional = false, cascade = CascadeType.PERSIST)
    private VehicleLicenceTypeEntity vehicleLicenceType;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getColour() {
        return colour;
    }

    public void setColour(String colour) {
        this.colour = colour;
    }

    public Boolean getDeleted() {
        return deleted;
    }

    public void setDeleted(Boolean deleted) {
        this.deleted = deleted;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getMakeAndModel() {
        return makeAndModel;
    }

    public void setMakeAndModel(String makeAndModel) {
        this.makeAndModel = makeAndModel;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getYear() {
        return year;
    }

    public void setYear(Integer year) {
        this.year = year;
    }

    public VehicleTypeEntity getVehicleType() {
        return vehicleType;
    }

    public void setVehicleType(VehicleTypeEntity vehicleType) {
        this.vehicleType = vehicleType;
    }

    public VehicleLicenceTypeEntity getVehicleLicenceType() {
        return vehicleLicenceType;
    }

    public void setVehicleLicenceType(VehicleLicenceTypeEntity vehicleLicenceType) {
        this.vehicleLicenceType = vehicleLicenceType;
    }

    // Transfer Object Methods
    public VehicleTO getData() {
        return new VehicleTO(id, name, colour, vehicleType.getData(), vehicleLicenceType.getData());
    }

    public VehicleDetailedTO getDetailedData() {
        return new VehicleDetailedTO(id, name, description, makeAndModel, colour, year, vehicleType.getData(), vehicleLicenceType.getData());
    }

    public void setData(VehicleDetailedTO to) {
        this.setName(to.getName());
        this.setDescription(to.getDescription());
        this.setMakeAndModel(to.getMakeAndModel());
        this.setColour(to.getColour());
        this.setYear(to.getYear());
    }

    @Override
    public String toString() {
        return "au.edu.swin.swinvehicle.vehicle.VehicleEntity[id=" + id + "]";
    }
}
